<template>
	<page>
		<!--		好友列表-->
		<view class="friend-info">
			<view class="info-title">
				<text>好友请求</text>
			</view>
			<view class="friend-list">
				<view class="list" v-for="(item,index) in applyList" :key="index">
					<view class="pic">
						<fui-avatar :src="item.user_info.avatar_pic" width="80" height="80" shape="square"></fui-avatar>
					</view>
					<view class="name-info">
						<view class="name">
							<text>{{item.user_info.nickname}}</text>
						</view>
						<view class="desc">
							<text>{{item.desc}}</text>
						</view>
					</view>
					<view class="status-info">
						<view class="btn" @click="onAgreeFriend(item,index)" v-if="item.status === 0">
							<text>同意</text>
						</view>
						<view class="status" v-else-if="item.status === 1">
							<text>已添加</text>
						</view>
						<view class="status" v-else-if="item.status === 2">
							<text>已拒绝</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</page>
</template>

<script setup>

import {getCurrentInstance, ref} from "vue";
import {agreeFriend, friendNoticeList} from "../../api/api";
import {onLoad} from "@dcloudio/uni-app";
import {useStore} from "vuex";

const { proxy } = getCurrentInstance();
const store = useStore();
const applyList = ref([]);

onLoad(() =>{
	getData();
})

function getData(){
	friendNoticeList({

	}).then(res =>{
		applyList.value = res.data;
	})
}

/**
 * 同意好友点击
 * @param item
 * @param index
 */
function onAgreeFriend(item,index){
	agreeFriend({
		friend_notice_id: item.friend_notice_id,
	}).then(res =>{
		proxy.$way.toast(res.msg);
		applyList.value[index].status = 1;
    store.commit('setCountFriendMsg',store.state.chat.countFriendMsg - 1);
	})
}
</script>

<style lang="scss">
	@import "FirendNotice.scss";
</style>
